package org.itstack.state.order;

/**
 * 待支付状态
 * 订单创建后的初始状态，等待用户支付
 * 
 * 设计原则：
 * - 单一职责：只负责待支付状态的行为
 * - 里氏替换：可以替换抽象订单状态
 */
public class PendingPaymentState implements OrderState {
    
    @Override
    public String getStateName() {
        return "待支付";
    }
    
    @Override
    public String getStateDescription() {
        return "订单已创建，等待用户支付";
    }
    
    @Override
    public void handleAction(OrderContext context, OrderAction action) {
        switch (action) {
            case PAY:
                System.out.println(String.format("订单 %s 支付成功，金额: %.2f", 
                    context.getOrderId(), context.getAmount()));
                context.setState(new PaidState());
                break;
            case CANCEL:
                System.out.println(String.format("订单 %s 已取消", context.getOrderId()));
                context.setState(new CancelledState());
                break;
            default:
                System.out.println(String.format("订单 %s 在待支付状态下无法执行 %s 操作", 
                    context.getOrderId(), action.getName()));
        }
    }
    
    @Override
    public boolean canExecuteAction(OrderAction action) {
        return action == OrderAction.PAY || action == OrderAction.CANCEL;
    }
}
